//
//  SMHMineOrderView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/4.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import ReactiveCocoa


class SMHMineOrderView: LZBaseView {
    
    var viewModel : SMHMineViewModel?

    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as? SMHMineViewModel

        setupUI() 
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:setupUI
    func setupUI() {
        
        let orderLab = UILabel()
        orderLab.text = "我的订单"
        orderLab.font = ktextBoldFont(size: 15)
        orderLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        addSubview(orderLab)
        orderLab.snp.makeConstraints { (make) in
            make.left.equalTo(20)
            make.top.equalTo(10)
            make.width.equalTo(150)
            make.height.equalTo(15)
        }
        
        
        let lineView = UIView()
        lineView.backgroundColor = UIColorFromHex(rgbValue: 0xE5E5E5)
        addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(38)
            make.height.equalTo(0.5)
        }
        
        
        let infoName = ["全部", "待付款", "待发货", "已发货", "已完成"]
        let infoImageName :[String] = ["icon_mine_all","icon_mine_pay","icon_mine_delivered","icon_mine_received","icon_mine_completed"]
        let infoBtnWidth :CGFloat = (kScreenWidth - 30) / CGFloat(infoName.count);
        for (idex,item) in infoName.enumerated(){
            
            let infoBtn = UIButton.init(type: .custom)
            let imageName = infoImageName[idex]
            infoBtn.setImage(UIImage.init(named: imageName), for: .normal)
            infoBtn.setTitle(item, for: .normal)
            infoBtn.tag = 100 + idex
            infoBtn.setTitleColor(UIColorFromHex(rgbValue: 0x363636), for: .normal)
            infoBtn.titleLabel?.font = ktextFont(size: 12)
            addSubview(infoBtn)
            
            infoBtn.snp.makeConstraints { (make) in
                make.left.equalTo(idex * Int(infoBtnWidth))
                make.top.equalTo(53)
                make.width.equalTo(infoBtnWidth)
                make.height.equalTo(46)
            }
            
            
            let badgeLab = UILabel()
            badgeLab.backgroundColor = UIColorFromHex(rgbValue: 0xFF661B)
            infoBtn.addSubview(badgeLab)
            badgeLab.snp.makeConstraints { (make) in
                make.centerX.equalTo(infoBtn.snp.centerX).offset(12)
                make.width.height.equalTo(10)
                make.top.equalTo(infoBtn.snp.top).offset(-3)
            }
            badgeLab.clipRectCorner(direction: .allCorners, cornerRadius: 5)
            infoBtn.layoutButtonEdgeInsets(style: .ButtonEdgeInsetsStyleTop, space: 6)
            
            infoBtn.reactive.controlEvents(.touchUpInside).observeValues { (button) in
                let orderVC = SMHMyOrderViewController.init()
                orderVC.title = "我的的订单"
                orderVC.index = idex
                orderVC.type = "123"
                currentVC()?.navigationController?.pushViewController(orderVC, animated: true)
            }
            
        }
        
        
    }
}
